package com.idealighter.game.dictionary.dic;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import com.idealighter.game.dictionary.core.DictionaryTable;
import com.idealighter.game.dictionary.domain.ShuihuBonusOuterKickOutDomain;
import com.idealighter.game.dictionary.mapper.ShuihuBonusOuterKickOutMapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Singleton
public class ShuihuBonusOuterKickOutDic implements DictionaryTable<ShuihuBonusOuterKickOutDomain> {
  private ShuihuBonusOuterKickOutMapper mapper;
  private List<ShuihuBonusOuterKickOutDomain> list;
  private Map<Integer, ShuihuBonusOuterKickOutDomain> map;

  @Inject
  public ShuihuBonusOuterKickOutDic(ShuihuBonusOuterKickOutMapper mapper) {
    this.mapper = mapper;
    load();
  }

  @Override
  public List<ShuihuBonusOuterKickOutDomain> list() {
    return list;
  }

  @Override
  public Map<Integer, ShuihuBonusOuterKickOutDomain> map() {
    return map;
  }

  @Override
  public void load() {
    this.list = mapper.selectAll();
    Map<Integer, ShuihuBonusOuterKickOutDomain> map =
        new HashMap<Integer, ShuihuBonusOuterKickOutDomain>();
    if (list != null && list.size() > 0) {
      for (ShuihuBonusOuterKickOutDomain item : list) {
        map.put((int) item.getIconId(), item);
      }
    }
    this.map = map;
  }

  @Override
  public ShuihuBonusOuterKickOutDomain get(int id) {
    ShuihuBonusOuterKickOutDomain result = null;
    if (map != null) {
      result = map.get(id);
    }
    return result;
  }

}
